﻿using System;
using System.Windows;
using LibVLCSharp.Shared;

namespace rpaly
{
    public partial class MainWindow : Window
    {
        private LibVLC _libVLC;
        private MediaPlayer _mediaPlayer;
        private Media media;
        public MainWindow()
        {
            InitializeComponent();

            // 初始化 LibVLC 和 MediaPlayer
            Core.Initialize();
            _libVLC = new LibVLC();
            _mediaPlayer = new MediaPlayer(_libVLC)
            {
                EnableHardwareDecoding = true
            };
            VideoViewPlayer.MediaPlayer = _mediaPlayer;

            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // 设置 RTSP URL 并播放
             media = new Media(_libVLC, new Uri("rtsp://192.168.31.128/test.mkv"));
           
        }

        protected override void OnClosed(EventArgs e)
        {
            // 释放资源
            _mediaPlayer.Dispose();
            _libVLC.Dispose();
            base.OnClosed(e);
        }

        private void Play_Click(object sender, RoutedEventArgs e)
        {
            _mediaPlayer.Play(media);
        }

        private void Stop_Click(object sender, RoutedEventArgs e)
        {
            _mediaPlayer.Stop();
        }

        private void Pause_Click(object sender, RoutedEventArgs e)
        {
            _mediaPlayer.Pause();
        }

        private void Continue_Click(object sender, RoutedEventArgs e)
        {
            _mediaPlayer.Play();
        }
    }
}
